<html>
<head><meta charset="utf-8"><title>SIMD Pointers · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html">SIMD Pointers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237711063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237711063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237711063">(May 06 2021 at 18:56)</a>:</h4>
<p>Hmm.<br>
I was going to say "cptr and mptr are unnecessary, we could have one monomorphized SIMD pointer type" but then I saw the differing impls of their actual types, and realized that we'd want to enable SIMD gather/scatter for replace, which requires <code>*mut</code> pointers, so yeah. Definitely going to have two SIMD pointer types. Oh well! No problem, honestly.</p>



<a name="237711555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237711555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237711555">(May 06 2021 at 19:00)</a>:</h4>
<p>Do any scatter/gather instructions actually take pointers via simd registers?</p>



<a name="237711737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237711737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237711737">(May 06 2021 at 19:00)</a>:</h4>
<p>x86-64 uses a GP register for the pointer and then specifies offsets via the SIMD type (and that simd type has the element width, not pointer width)</p>



<a name="237712000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237712000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237712000">(May 06 2021 at 19:02)</a>:</h4>
<p>ooh, good question.</p>



<a name="237712158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237712158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237712158">(May 06 2021 at 19:03)</a>:</h4>
<p>I would hazard a guess that the answer is no since SIMD doesn't really interact with memory?</p>



<a name="237712254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237712254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237712254">(May 06 2021 at 19:04)</a>:</h4>
<p>At least not in any regular way</p>



<a name="237712982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237712982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237712982">(May 06 2021 at 19:08)</a>:</h4>
<p>what does the "vm32x" here in the operands mean?<br>
<a href="https://www.felixcloutier.com/x86/vgatherdps:vgatherqps">https://www.felixcloutier.com/x86/vgatherdps:vgatherqps</a><br>
I usually can puzzle things out but my brain is stalling.<br>
And then the AVX512 instructions look like they're subtly different...</p>



<a name="237713072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713072">(May 06 2021 at 19:09)</a>:</h4>
<p>vector mask, 32 bits, {x,y}mm register?</p>



<a name="237713100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713100">(May 06 2021 at 19:09)</a>:</h4>
<p>I'm not sure where that terminology comes from, but that's the GP register</p>



<a name="237713110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713110">(May 06 2021 at 19:09)</a>:</h4>
<p>Pretty sure</p>



<a name="237713383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713383">(May 06 2021 at 19:11)</a>:</h4>
<blockquote>
<p>There's a note in Codegen.hs about how I didn't know what vm32x vm32y vm64x vm64y are.</p>
<p>They're 32 and 64-bit memory operands. We can finally support vgatherpd. Woo.</p>
</blockquote>
<p>aha, you're right.</p>



<a name="237713485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713485">(May 06 2021 at 19:12)</a>:</h4>
<p>I... think?</p>



<a name="237713791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713791">(May 06 2021 at 19:15)</a>:</h4>
<blockquote>
<div class="codehilite"><pre><span></span><code>&quot;vm32x&quot;
   A vector of memory addresses using VSIB with 32-bit indices in XMM register.
</code></pre></div>

</blockquote>
<p>oh no!<br>
<a href="https://pkg.go.dev/github.com/mmcloughlin/avo/internal/opcodesxml?utm_source=godoc">https://pkg.go.dev/github.com/mmcloughlin/avo/internal/opcodesxml?utm_source=godoc</a><br>
thank you Go, I can at least appreciate your fondness for documentation.</p>



<a name="237713819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713819">(May 06 2021 at 19:15)</a>:</h4>
<p>Hmm</p>



<a name="237713834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713834">(May 06 2021 at 19:15)</a>:</h4>
<p>yeah, it basically is just "a vector of pointers"</p>



<a name="237713973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237713973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237713973">(May 06 2021 at 19:16)</a>:</h4>
<p>the <em>intrinsics</em> do happen to work like "offsets from a base, potentially masked".</p>



<a name="237714133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714133">(May 06 2021 at 19:17)</a>:</h4>
<p>I'm very confused what vm64x is for example</p>



<a name="237714165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714165">(May 06 2021 at 19:17)</a>:</h4>
<p>Wouldn't you need two xmm registers for that?</p>



<a name="237714245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714245">(May 06 2021 at 19:18)</a>:</h4>
<p>For vgatherqps</p>



<a name="237714447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714447">(May 06 2021 at 19:19)</a>:</h4>
<p>Oh no, it just loads half as many</p>



<a name="237714448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714448">(May 06 2021 at 19:19)</a>:</h4>
<blockquote>
<p>VEX.128 version: For dword indices, the instruction will gather four single-precision floating-point values. For qword indices, the instruction will gather two values and zero the upper 64 bits of the destination.</p>
</blockquote>



<a name="237714461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714461">(May 06 2021 at 19:19)</a>:</h4>
<p>Yeah.</p>



<a name="237714472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714472">(May 06 2021 at 19:20)</a>:</h4>
<p>yep</p>



<a name="237714583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714583">(May 06 2021 at 19:20)</a>:</h4>
<p>So the thing that gets weird here is 32-bit pointers</p>



<a name="237714605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714605">(May 06 2021 at 19:20)</a>:</h4>
<p>yeeeeeeeeeeeeeEEEP</p>



<a name="237714640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714640">(May 06 2021 at 19:21)</a>:</h4>
<p>Which certainly explains why the intrinsic uses a base pointer only</p>



<a name="237714771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714771">(May 06 2021 at 19:22)</a>:</h4>
<p>I am slowly materializing a design in my head but there is a reason why I wanted to open the floor for banter, which is "lol, this is gonna be weird no matter how we do it".</p>



<a name="237714963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714963">(May 06 2021 at 19:23)</a>:</h4>
<p>I'm pretty sure we just ignore the concept of the 32-bit pointers and hope llvm optimizes it</p>



<a name="237714989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237714989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237714989">(May 06 2021 at 19:23)</a>:</h4>
<p>Looks like llvm ignores it</p>



<a name="237715007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715007">(May 06 2021 at 19:23)</a>:</h4>
<p>They just take pointer vectors directly</p>



<a name="237715157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715157">(May 06 2021 at 19:25)</a>:</h4>
<p>Okay, LLVM thinks of this as pointer vectors? Cool, then yeah, I think we should angle for basically using SIMD pointer types as a result. I want to talk to wg-unsafe-code-guidelines though, thinking about it, because I want to know if we're gonna break the world if e.g. we enable easily using SIMD gather on, say, multiple slices in memory.</p>



<a name="237715231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715231">(May 06 2021 at 19:25)</a>:</h4>
<p>multiple slices in memory that may not be part of the same superstructure.</p>



<a name="237715248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715248">(May 06 2021 at 19:25)</a>:</h4>
<p>Hm you've lost me there</p>



<a name="237715326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715326">(May 06 2021 at 19:26)</a>:</h4>
<p>Basically the question is:<br>
"does the entire gather have to be 'in-bounds' for some memory object?"</p>



<a name="237715366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715366">(May 06 2021 at 19:26)</a>:</h4>
<p>What's a "memory object"?</p>



<a name="237715368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715368">(May 06 2021 at 19:26)</a>:</h4>
<p>"or can it be 'in-bounds' for multiple <em>different</em> memory objects?"</p>



<a name="237715403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715403">(May 06 2021 at 19:26)</a>:</h4>
<p>a struct, slice of bytes, etc.</p>



<a name="237715471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715471">(May 06 2021 at 19:27)</a>:</h4>
<p>Basically, what kind of provenance does a vector of pointers need.</p>



<a name="237715503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715503">(May 06 2021 at 19:27)</a>:</h4>
<p>Well they're just pointers</p>



<a name="237715523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715523">(May 06 2021 at 19:27)</a>:</h4>
<p>The function is unsafe inherently</p>



<a name="237715621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715621">(May 06 2021 at 19:28)</a>:</h4>
<p>But for a gather the pointers need to be readable and for scatter they need to be writable</p>



<a name="237715640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715640">(May 06 2021 at 19:28)</a>:</h4>
<p>That's it</p>



<a name="237715664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715664">(May 06 2021 at 19:28)</a>:</h4>
<p>yep! which is why, before I provide such a function, I want to be able to say <em>something</em> about what gathers and scatters are UB, with relative confidence.</p>



<a name="237715674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715674">(May 06 2021 at 19:29)</a>:</h4>
<p>You need to hold all of the pointers uniquely for a scatter</p>



<a name="237715704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715704">(May 06 2021 at 19:29)</a>:</h4>
<p>And you need to hold all of them immutably for a gather</p>



<a name="237715726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715726">(May 06 2021 at 19:29)</a>:</h4>
<p>I don't think it's any different than ptr read/write</p>



<a name="237715739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715739">(May 06 2021 at 19:29)</a>:</h4>
<p>sure it is.</p>



<a name="237715748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237715748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237715748">(May 06 2021 at 19:29)</a>:</h4>
<p>Why?</p>



<a name="237716999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237716999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237716999">(May 06 2021 at 19:38)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">ManyValues</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="cm">/*  A facade for an array, maybe allocated somewhere, of initialized values. At least 2. */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">ManyValues</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">new</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cm">/* does the obvious */</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">as_ptr</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cm">/* does the obvious */</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">aa</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ab</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ac</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ad</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">all</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">aa</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ab</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ac</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ad</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">()];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">vals</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">SimdPtr</span>::<span class="n">from_array</span><span class="p">(</span><span class="n">all</span><span class="p">).</span><span class="n">add</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">gather</span><span class="p">()</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
</code></pre></div>
<p>So the question is if <em>this</em> is UB or not, because individually those reads are valid, but only because they are each in-bounds of their original object.</p>



<a name="237717084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717084">(May 06 2021 at 19:39)</a>:</h4>
<p>I don't understand what in-bounds means</p>



<a name="237717141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717141">(May 06 2021 at 19:39)</a>:</h4>
<p>a read is in-bounds if it's actually reading data from the memory object.</p>



<a name="237717157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717157">(May 06 2021 at 19:39)</a>:</h4>
<p>to simplify.</p>



<a name="237717238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717238">(May 06 2021 at 19:40)</a>:</h4>
<p>"a valid index", basically.</p>



<a name="237717298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717298">(May 06 2021 at 19:40)</a>:</h4>
<p>"a read that does not contain Bonus Data" per <a href="https://twitter.com/dril_rs/status/1230334918560890882">https://twitter.com/dril_rs/status/1230334918560890882</a></p>
<div class="inline-preview-twitter"><div class="twitter-tweet"><a href="https://twitter.com/dril_rs/status/1230334918560890882"><img class="twitter-avatar" src="https://uploads.zulipusercontent.net/041916194bb410af5ffe571160cb872b3c2ace27/68747470733a2f2f7062732e7477696d672e636f6d2f70726f66696c655f696d616765732f313033343935363333343930353631303234312f357071686c69655f5f6e6f726d616c2e6a7067"></a><p>one of the things i dont “get” about rustc is why can’t you index out of bounds. c gives me “bonus data” but no. rustc always jsut gives me shit</p><span>- wint32_t (@dril_rs)</span></div></div>



<a name="237717351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717351">(May 06 2021 at 19:41)</a>:</h4>
<p>You can do <code>array.as_ptr().add(1).read()</code> as long as the pointer is valid to read under the mutability rules</p>



<a name="237717382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717382">(May 06 2021 at 19:41)</a>:</h4>
<p>Where the pointer "came from" doesn't matter</p>



<a name="237717545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237717545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237717545">(May 06 2021 at 19:42)</a>:</h4>
<p>If you allocate two entirely different objects adjacent in memory with mmap and index off of one mapping into the other it's still valid as long as you treat mutability of that address correctly</p>



<a name="237718841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237718841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237718841">(May 06 2021 at 19:53)</a>:</h4>
<p>I do not think that is entirely correct, due to the implications of provenance:<br>
<a href="https://www.ralfj.de/blog/2020/12/14/provenance.html">https://www.ralfj.de/blog/2020/12/14/provenance.html</a><br>
<a href="https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html">https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html</a></p>
<blockquote>
<p>Just because two pointers point to the same address, does not mean they are equal and can be used interchangeably.</p>
</blockquote>



<a name="237721442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237721442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237721442">(May 06 2021 at 20:14)</a>:</h4>
<p>That's in the context of optimization, though.  Not at the language level</p>



<a name="237721590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237721590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237721590">(May 06 2021 at 20:15)</a>:</h4>
<p>Otherwise you wouldn't be able to do things like use the high pointer bit for short string optimization</p>



<a name="237721822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237721822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237721822">(May 06 2021 at 20:17)</a>:</h4>
<p>A huge number of Linux APIs involve conditionally casting extra elements to structs that sometimes contain pointers</p>



<a name="237722255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237722255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237722255">(May 06 2021 at 20:21)</a>:</h4>
<p>I have a <em>reasonable</em> confidence that the example code is <em>probably</em> valid, but can you see why I want to run it by WUCG first, now? :^)</p>



<a name="237722808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237722808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237722808">(May 06 2021 at 20:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237717351">said</a>:</p>
<blockquote>
<p>You can do <code>array.as_ptr().add(1).read()</code> as long as the pointer is valid to read under the mutability rules</p>
</blockquote>
<p>that's wrong: from the <code>add</code> docs:</p>
<blockquote>
<p>If any of the following conditions are violated, the result is Undefined Behavior:</p>
<p>Both the starting and resulting pointer must be either in bounds or one byte past the end of the same allocated object. Note that in Rust, every (stack-allocated) variable is considered a separate allocated object.</p>
</blockquote>



<a name="237722940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237722940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237722940">(May 06 2021 at 20:26)</a>:</h4>
<p>if you want to go from 1 allocated object to another, you have to use <code>wrapping_add</code></p>



<a name="237723453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237723453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237723453">(May 06 2021 at 20:30)</a>:</h4>
<p>Hmm yeah I suppose I meant wrapping add, yeah</p>



<a name="237723489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237723489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237723489">(May 06 2021 at 20:31)</a>:</h4>
<p>But my point in general stands that you can cross objects</p>



<a name="237723515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237723515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237723515">(May 06 2021 at 20:31)</a>:</h4>
<p>So, for some reason llvm doesn't compile  a gather load from a vector of pointers to <code>i32</code> into one or more AVX2<code>vgatherqps</code> even though it should...<code>vgatherqps</code> with zero put in the base reg and the pointer vector as the index reg should work just fine.<br>
<a href="https://llvm.godbolt.org/z/WsT3xPrME">https://llvm.godbolt.org/z/WsT3xPrME</a></p>



<a name="237724545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724545">(May 06 2021 at 20:38)</a>:</h4>
<p>Linux isn't yet written in Rust, so don't assume it's rules always apply for us</p>



<a name="237724610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724610">(May 06 2021 at 20:38)</a>:</h4>
<p>So it's UB to call Linux syscalls?</p>



<a name="237724690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724690">(May 06 2021 at 20:39)</a>:</h4>
<p>Well, particularly: you <strong>cannot</strong> use wrapping add to cross object boundaries. You can use wrapping add to go out of bounds but you have to go back in bounds again before using the pointer, or it's UB.</p>



<a name="237724702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724702">(May 06 2021 at 20:39)</a>:</h4>
<p>It would also be impossible to write a C frontend in LLVM if that's the case, since two identical pointers _are_ the same and are frequently converted through integers</p>



<a name="237724707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724707">(May 06 2021 at 20:39)</a>:</h4>
<p>FFI is written very carefully. <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="237724835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724835">(May 06 2021 at 20:40)</a>:</h4>
<p>pointer/int casts are like an entire RalfJ blog post just to introduce the problem, i cannot solve it right here on my phone XD</p>



<a name="237724942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724942">(May 06 2021 at 20:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237724702">said</a>:</p>
<blockquote>
<p>It would also be impossible to write a C frontend in LLVM if that's the case, since two identical pointers _are_ the same and are frequently converted through integers</p>
</blockquote>
<p>I mean... I consider the proposition that it is possible to write a correct C compiler to be currently unproven, and the proposition that LLVM is one doubly so. It implements <strong>a</strong> behavior, that doesn't mean it's a correct one.</p>



<a name="237724958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237724958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237724958">(May 06 2021 at 20:41)</a>:</h4>
<p><a href="https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html">https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html</a></p>
<p><a href="https://www.ralfj.de/blog/2020/12/14/provenance.html">https://www.ralfj.de/blog/2020/12/14/provenance.html</a></p>
<p>whoops did i say one post? i meant two blog posts</p>



<a name="237725143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725143">(May 06 2021 at 20:43)</a>:</h4>
<p>Yeah I already linked those~</p>



<a name="237725190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725190">(May 06 2021 at 20:43)</a>:</h4>
<p>So following those optimization rules I still don't see how that affects scatter/gather</p>



<a name="237725263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725263">(May 06 2021 at 20:44)</a>:</h4>
<p>If your pointers are created properly you can use them</p>



<a name="237725485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725485">(May 06 2021 at 20:46)</a>:</h4>
<p>oh my gosh you did link them</p>



<a name="237725598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725598">(May 06 2021 at 20:46)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> correct: if you do it carefully you can use the pointer</p>



<a name="237725732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237725732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237725732">(May 06 2021 at 20:47)</a>:</h4>
<p>note that, for example, I don't have wrappers for these ops in safe_arch because making a good interface for it was, at the time, "more trouble than i wanted to deal with"</p>



<a name="237729425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237729425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237729425">(May 06 2021 at 21:06)</a>:</h4>
<p>Got it to generate <code>vgatherqps</code>, turns out I needed to use <code>-O3 -march=skylake</code>:<br>
<a href="https://llvm.godbolt.org/z/MParP6Ys4">https://llvm.godbolt.org/z/MParP6Ys4</a></p>



<a name="237732340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237732340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237732340">(May 06 2021 at 21:20)</a>:</h4>
<p>My understanding is that gather on most x86 uarches actually does nothing</p>



<a name="237735245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237735245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237735245">(May 06 2021 at 21:42)</a>:</h4>
<p>really? that sucks.</p>



<a name="237735809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237735809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237735809">(May 06 2021 at 21:47)</a>:</h4>
<p>it also works on risc-v v (and SimpleV and probably ARM SVE):<br>
<a href="https://llvm.godbolt.org/z/WejPcoxro">https://llvm.godbolt.org/z/WejPcoxro</a></p>



<a name="237736867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237736867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237736867">(May 06 2021 at 21:57)</a>:</h4>
<p>Yeah except for a few cpus it just does normal sequential loads</p>



<a name="237736926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237736926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237736926">(May 06 2021 at 21:58)</a>:</h4>
<p>Reduces your number of instructions but that's it</p>



<a name="237736969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237736969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237736969">(May 06 2021 at 21:58)</a>:</h4>
<p>Eh, I guess that's worth it, tbh.</p>



<a name="237737007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237737007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237737007">(May 06 2021 at 21:58)</a>:</h4>
<p>Maybe slightly but hardly</p>



<a name="237737826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237737826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237737826">(May 06 2021 at 22:05)</a>:</h4>
<blockquote>
<p>2.3.12  Vector SIB (VSIB) Memory Addressing</p>
</blockquote>
<p>wow I was wrong, it's a totally wild <strong>exotic memory encoding</strong>.</p>



<a name="237741071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237741071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237741071">(May 06 2021 at 22:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237737007">said</a>:</p>
<blockquote>
<p>Maybe slightly but hardly</p>
</blockquote>
<p>I should note that I was just sort of assuming that generating a vector gather will allow for graceful acceleration here as arches improve, assuming it's a correct instruction to lower to. However, it's actually slower to lower to a gather in the simple case!<br>
<a href="https://stackoverflow.com/questions/24756534/in-what-situation-would-the-avx2-gather-instructions-be-faster-than-individually">https://stackoverflow.com/questions/24756534/in-what-situation-would-the-avx2-gather-instructions-be-faster-than-individually</a><br>
which sucks.</p>



<a name="237741422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237741422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237741422">(May 06 2021 at 22:38)</a>:</h4>
<p>Great lol</p>



<a name="237741671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237741671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237741671">(May 06 2021 at 22:42)</a>:</h4>
<p>though I actually didn't bench it against compiler output, this is being measured against hand-assembler, and while compilers <em>say</em> they provide zero cost abstractions... well, Uhmmm, Not Always.</p>



<a name="237742467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237742467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237742467">(May 06 2021 at 22:51)</a>:</h4>
<p>it greatly depends on the cpu, which is why llvm will scalarize a vector gather on haswell (since that's faster there) and generate a <code>vgather*</code> on skylake (since that's faster there).</p>



<a name="237761785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237761785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237761785">(May 07 2021 at 03:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237716999">said</a>:</p>
<blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">ManyValues</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="cm">/*  A facade for an array, maybe allocated somewhere, of initialized values. At least 2. */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">ManyValues</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">new</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cm">/* does the obvious */</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">as_ptr</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cm">/* does the obvious */</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">aa</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ab</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ac</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ad</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ManyValues</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">all</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">aa</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ab</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ac</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">(),</span><span class="w"> </span><span class="n">ad</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">()];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">vals</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">SimdPtr</span>::<span class="n">from_array</span><span class="p">(</span><span class="n">all</span><span class="p">).</span><span class="n">add</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="n">gather</span><span class="p">()</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
</code></pre></div>
<p>So the question is if <em>this</em> is UB or not, because individually those reads are valid, but only because they are each in-bounds of their original object.</p>
</blockquote>
<p>What does this <code>SimdPtr::from_array(all).add(1).gather()</code> line do? (I googled <code>SimdPtr</code> but it seems this is psuedocode.) Is it reading from the four pointers as in <code>let vals = [*all[0], *all[1], *all[2], *all[3]];</code>? Because that is not UB, it's just four loads. If you are making some assumptions about <code>aa, ab, ac, ad</code> being adjacent in memory though that's a no-no</p>



<a name="237762019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762019">(May 07 2021 at 03:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237724702">said</a>:</p>
<blockquote>
<p>It would also be impossible to write a C frontend in LLVM if that's the case, since two identical pointers _are_ the same and are frequently converted through integers</p>
</blockquote>
<p>This is very misleading. At the end of the day pointers are represented as integers in hardware, but the day is long and has many compiler optimizations in it that treat two bitwise identical pointers as distinct</p>



<a name="237762058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762058">(May 07 2021 at 03:14)</a>:</h4>
<p>At the language level, there is more to a pointer than just the bits. I'm not entirely convinced that the overall model is sound but the fact of the matter is that the abstract rust machine has a bunch of auxiliary extra data stuck on to the actual bits</p>



<a name="237762157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762157">(May 07 2021 at 03:15)</a>:</h4>
<p>It is perfectly valid, for example, for an operating system to define certain addresses to have certain meanings and you can pull those pointers out of thin air</p>



<a name="237762207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762207">(May 07 2021 at 03:16)</a>:</h4>
<p>I understand that pointer _arithmetic_ might make certain assumptions, but even then things like SSO are valid</p>



<a name="237762266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762266">(May 07 2021 at 03:17)</a>:</h4>
<p>The reason I was concerned about thinking this would relate to scatter/gather at all is because there's simply no arithmetic involved</p>



<a name="237762337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762337">(May 07 2021 at 03:18)</a>:</h4>
<p>well i suspect that it's ill defined but i also suspect you can't scatter to a place you don't have write permission to and you can't gather from a place you don't have read permission from</p>



<a name="237762378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762378">(May 07 2021 at 03:19)</a>:</h4>
<p>Yeah, I expect it has identical semantics to regular pointer read/write</p>



<a name="237762488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762488">(May 07 2021 at 03:20)</a>:</h4>
<p>I will say that you can do this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">array_here_at_least_2_elements</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="n">a</span><span class="p">.</span><span class="n">as_ptr</span><span class="p">().</span><span class="n">add</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
</code></pre></div>
<p>but that's because  the <code>as_ptr</code> value can access to "the whole array", so when you add by 1 you're just indexing to element 1 more verbosely.</p>



<a name="237762597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762597">(May 07 2021 at 03:22)</a>:</h4>
<p>so if we understand scatter/gather as being "weirdly compact indexing", then it's easy to understand the rules</p>



<a name="237762828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762828">(May 07 2021 at 03:25)</a>:</h4>
<p>Looking more into this, getelementptr absolutely allows pointers to be willed out of thin air</p>



<a name="237762911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762911">(May 07 2021 at 03:26)</a>:</h4>
<p>If you use the "inbounds" optimization it will track the pointer through arithmetic</p>



<a name="237762916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762916">(May 07 2021 at 03:26)</a>:</h4>
<p>Which looks like what <span class="user-mention" data-user-id="281757">@Jubilee</span> was referencing</p>



<a name="237762928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762928">(May 07 2021 at 03:27)</a>:</h4>
<p>But there's no overall assumption that you need to follow rules like that</p>



<a name="237762958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237762958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237762958">(May 07 2021 at 03:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237762157">said</a>:</p>
<blockquote>
<p>It is perfectly valid, for example, for an operating system to define certain addresses to have certain meanings and you can pull those pointers out of thin air</p>
</blockquote>
<p>Pointers which are created directly from integers have a provenance of their own, different from the provenance of pointers created by (the equivalent of) malloc which is "magic"</p>



<a name="237763042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763042">(May 07 2021 at 03:29)</a>:</h4>
<p>Yeah that's what I was trying to get at--if you don't use the "inbounds" optimization it doesn't particularly care about provenance</p>



<a name="237763074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763074">(May 07 2021 at 03:29)</a>:</h4>
<p>A language like C does not have that concept so if it's using that optimization it better be careful to assert the programmer didn't intentionally cross an object boundary</p>



<a name="237763082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763082">(May 07 2021 at 03:29)</a>:</h4>
<p>The semantics of scatter/gather is underdetermined by the hardware, which doesn't operate on provenance. It is compiler developers and language folks who fill in the story around how the extra ghost state is manipulated, and the obvious thing is to make it act like a read</p>



<a name="237763172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763172">(May 07 2021 at 03:30)</a>:</h4>
<p>But it is important that say LLVM and Rust agree on how that extra state is handled</p>



<a name="237763293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763293">(May 07 2021 at 03:32)</a>:</h4>
<p>Again since it's a read/write I don't see how provenance is relevant.  The UB would be an improper use of <code>pointer::add</code>, not scatter/gather</p>



<a name="237763382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763382">(May 07 2021 at 03:33)</a>:</h4>
<p>I admit I don't know what these simd operations actually do, but it sounds like gather is just 4 reads at once</p>



<a name="237763393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763393">(May 07 2021 at 03:33)</a>:</h4>
<p>Yeah that's all it is</p>



<a name="237763395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763395">(May 07 2021 at 03:33)</a>:</h4>
<p>in which case it would be UB if you read out of an allocation</p>



<a name="237763447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763447">(May 07 2021 at 03:34)</a>:</h4>
<p>although maybe there is some way to limit that to just producing <code>poison</code></p>



<a name="237763475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763475">(May 07 2021 at 03:34)</a>:</h4>
<p>Yeah, same as <code>pointer::read</code> as far as I can tell</p>



<a name="237763506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763506">(May 07 2021 at 03:35)</a>:</h4>
<p>As to whether simd <code>add</code> acts like <code>wrapping_add</code> or <code>add</code> (i.e. does it assert that the target is inbounds) I would lean towards <code>wrapping_add</code></p>



<a name="237763541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763541">(May 07 2021 at 03:35)</a>:</h4>
<p>but LLVM is the first mover here so we have to follow what they do</p>



<a name="237763605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763605">(May 07 2021 at 03:36)</a>:</h4>
<p>If it's implemented with simd add, yes it would be like wrapping_add</p>



<a name="237763634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763634">(May 07 2021 at 03:36)</a>:</h4>
<p>The underlying type is just an integer</p>



<a name="237763663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763663">(May 07 2021 at 03:37)</a>:</h4>
<p>Whether the hardware wraps is independent of whether it is UB</p>



<a name="237763672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763672">(May 07 2021 at 03:37)</a>:</h4>
<p><code>pointer::add</code> is special because it's not implemented with addition at all, it's implemented with getelementptr</p>



<a name="237763701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763701">(May 07 2021 at 03:38)</a>:</h4>
<p>The UB question can only be decided by consulting the LLVM spec (such as it is) or whether there are any optimizations that make assumptions in violation of the spec we want</p>



<a name="237763763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763763">(May 07 2021 at 03:38)</a>:</h4>
<p>getelementptr is also "just an add" in hardware</p>



<a name="237763787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763787">(May 07 2021 at 03:38)</a>:</h4>
<p>but LLVM will translate adds to geps <em>and vice versa</em> so it's not as simple as you think</p>



<a name="237763791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763791">(May 07 2021 at 03:38)</a>:</h4>
<p>Agreed, but it has the option of the "inbounds" optimization, which is where the whole provenance question comes from</p>



<a name="237763800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763800">(May 07 2021 at 03:39)</a>:</h4>
<p>If you do not use that optimization it's not relevant</p>



<a name="237763829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763829">(May 07 2021 at 03:39)</a>:</h4>
<p>It's specifically only if you specifically <code>getelementptr inbounds</code></p>



<a name="237763843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763843">(May 07 2021 at 03:39)</a>:</h4>
<p>I'm inclined to agree with you here, I doubt simd add in LLVM has any kind of inbounds option</p>



<a name="237763898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763898">(May 07 2021 at 03:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237761785">said</a>:</p>
<blockquote>
<p>What does this <code>SimdPtr::from_array(all).add(1).gather()</code> line do? (I googled <code>SimdPtr</code> but it seems this is psuedocode.) Is it reading from the four pointers as in <code>let vals = [*all[0], *all[1], *all[2], *all[3]];</code>? Because that is not UB, it's just four loads. If you are making some assumptions about <code>aa, ab, ac, ad</code> being adjacent in memory though that's a no-no</p>
</blockquote>
<p>Yeah that is just pseudocode for a hypothetical SimdPtr type and yeah, <code>fn gather(self)</code> would just be "turn this from a vector of pointers into a vector of elements from those locations".</p>



<a name="237763918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763918">(May 07 2021 at 03:40)</a>:</h4>
<p>and I can only hope that if they see a simd add and unvectorize it they wouldn't be so foolish as to transform it into a gepi</p>



<a name="237763941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763941">(May 07 2021 at 03:40)</a>:</h4>
<p>There is no vector getelementptr in general</p>



<a name="237763965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237763965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237763965">(May 07 2021 at 03:41)</a>:</h4>
<p>You can only use regular arithmetic on vectors in LLVM</p>



<a name="237764082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764082">(May 07 2021 at 03:43)</a>:</h4>
<p>Though I do think we should consider adopting Intel's scatter/gather API to both avoid a simd pointer type, and to make it easy to work with smaller width pointers</p>



<a name="237764087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764087">(May 07 2021 at 03:43)</a>:</h4>
<p>luv 2 do raw pointer arithmetic.</p>



<a name="237764146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764146">(May 07 2021 at 03:44)</a>:</h4>
<p>Working with 2 64-bit pointer vectors to load a single vector of f32s doesn't seem practical</p>



<a name="237764188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764188">(May 07 2021 at 03:44)</a>:</h4>
<p>hmm? you mean basically taking a vector of indices into an alloc?</p>



<a name="237764247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764247">(May 07 2021 at 03:45)</a>:</h4>
<p>is there a version of gather that does <code>*(a+x_i)</code> where <code>a</code> is a GPR?</p>



<a name="237764320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764320">(May 07 2021 at 03:46)</a>:</h4>
<p>That's Intel's API</p>



<a name="237764321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764321">(May 07 2021 at 03:46)</a>:</h4>
<p>Yeah, that's basically how the intrinsic functions work.</p>



<a name="237764358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764358">(May 07 2021 at 03:46)</a>:</h4>
<p>but I guess the downside is that they all have the same base pointer, so if you want to gather from many different arrays you are in trouble</p>



<a name="237764500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237764500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237764500">(May 07 2021 at 03:48)</a>:</h4>
<p>unless you get lucky and the arrays are not too far apart in address space, and then you have to make accesses to multiple allocations from a single base pointer <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="237849716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237849716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237849716">(May 07 2021 at 16:16)</a>:</h4>
<p>Ah, I thought this one was gonna be a problem eventually.</p>
<p>So, IMO <code>V&lt;[*const T; N]&gt;</code> being the basis for scatter/gather isn't ideal. Doing it as (possibly masked) indexed offsets from a pointer (e.g. <code>unsafe fn gather(*const T, V&lt;[Int; N]&gt;)</code>) -&gt; V&lt;[T; N]&gt;` is much more natural most of the time. If there's hardware that needs it to be a vec of pointers, it's likely going to be easier to convert pointer + offsets into that, than vice versa too, I suspect. This also allows both checked and unchecked versions, where the checked version would gather from a slice. I think the bounds check should be relatively easy to write as simd, too (but we definitely need an unchecked version as well).</p>
<p>a big hassle though is that indexes on at least x86 are often based on i32, not usize <span aria-label="coffin" class="emoji emoji-26b0" role="img" title="coffin">:coffin:</span> (well, you have both i32 and 64 bit loads, but you kind of need both)</p>



<a name="237850685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237850685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237850685">(May 07 2021 at 16:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237713834">said</a>:</p>
<blockquote>
<p>yeah, it basically is just "a vector of pointers"</p>
</blockquote>
<p>i think you've been hit by the confusion inherent in x86's many addressing modes. in practice this is still base address and 32 bit indices (for the v32x).</p>



<a name="237850868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237850868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237850868">(May 07 2021 at 16:24)</a>:</h4>
<p>another nice thing about doing it based on 1 pointer (or slice) and offsets of that pointer is that i think the problems of provenance become way more natural to answer too</p>



<a name="237876129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237876129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237876129">(May 07 2021 at 19:17)</a>:</h4>
<p>I think we should have pointer vectors, and gather/scatter based on pointer vectors, since some algorithms require that in order to not be compiler-level UB:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[repr(C)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">LinkedListNode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">value</span>: <span class="kt">u64</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">next</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="sd">/// vector version</span>
<span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">next_vec</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">LANES</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">node_ptrs</span>: <span class="nc">SimdPtr</span><span class="o">&lt;</span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"> </span><span class="n">LANES</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">mask</span>: <span class="nc">MaskSize</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">SimdPtr</span><span class="o">&lt;</span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"> </span><span class="n">LANES</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">next_field_ptrs</span>: <span class="nc">SimdPtr</span><span class="o">&lt;*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"> </span><span class="n">LANES</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node_ptrs</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">offset_of</span><span class="o">!</span><span class="p">(</span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"> </span><span class="n">next</span><span class="p">));</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">passthru</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">SimdPtr</span>::<span class="o">&lt;</span><span class="n">LinkedListNode</span><span class="p">,</span><span class="w"> </span><span class="n">LANES</span><span class="o">&gt;</span>::<span class="n">splat</span><span class="p">(</span><span class="n">ptr</span>::<span class="n">null_mut</span><span class="p">());</span><span class="w"></span>
<span class="w">        </span><span class="c1">// important: every lane can point to a completely different node object.</span>
<span class="w">        </span><span class="c1">// mask is required since some node pointers could be null, and dereferencing a null ptr is UB</span>
<span class="w">        </span><span class="n">node_ptrs</span><span class="p">.</span><span class="n">gather_masked</span><span class="p">(</span><span class="n">mask</span><span class="p">,</span><span class="w"> </span><span class="n">passthru</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span><span class="c1">// should compile to:</span>
<span class="w">        </span><span class="c1">// %ymm0 = passthru</span>
<span class="w">        </span><span class="c1">// %ymm1 = node_ptrs</span>
<span class="w">        </span><span class="c1">// %ymm2 = mask</span>
<span class="w">        </span><span class="c1">// vpgatherqq %ymm0, [%ymm1 + 8], %ymm2</span>
<span class="w">        </span><span class="c1">// return %ymm0</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="sd">/// equivalent array version</span>
<span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">next_array</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">LANES</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">node_ptrs</span>: <span class="p">[</span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">],</span><span class="w"> </span><span class="n">masks</span>: <span class="p">[</span><span class="kt">bool</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="p">[</span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">next_field_ptrs</span>: <span class="p">[</span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node_ptrs</span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="n">v</span><span class="o">|</span><span class="w"> </span><span class="n">addr_of_mut</span><span class="o">!</span><span class="p">((</span><span class="o">*</span><span class="n">v</span><span class="p">).</span><span class="n">next</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">passthru</span>: <span class="p">[</span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">LinkedListNode</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">ptr</span>::<span class="n">null_mut</span><span class="p">();</span><span class="w"> </span><span class="n">LANES</span><span class="p">];</span><span class="w"></span>
<span class="w">        </span><span class="n">node_ptrs</span><span class="p">.</span><span class="n">zip</span><span class="p">(</span><span class="n">mask</span><span class="p">).</span><span class="n">zip</span><span class="p">(</span><span class="n">passthru</span><span class="p">).</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="p">((</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="n">mask</span><span class="p">),</span><span class="w"> </span><span class="n">passthru</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">mask</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="n">v</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">passthru</span><span class="w"> </span><span class="p">})</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Do note that at the x86 assembler level, for <code>vgatherqps %xmm0, [%rax + %ymm1], %xmm2</code>, it is valid for either the vector <code>%ymm1</code> or the base register <code>%rax</code> to be pointers, x86 doesn't have any of the compiler-only UB around address calculation or crossing allocations or wrapping, all it sees are 64-bit integers that it adds together then uses as addresses to load from.</p>
<p>I do think Intel made a mistake when they omitted gather-using-vector-of-pointers from their list of compiler intrinsics.</p>
<p>That said, I won't object to also having:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">LANES</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">SimdI32</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">gather_indexed_masked_f32</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">base</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">f32</span><span class="p">,</span><span class="w"> </span><span class="n">mask</span>: <span class="nc">Mask32</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">passthru</span>: <span class="nc">SimdF32</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">SimdF32</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="fm">todo!</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="237876849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237876849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237876849">(May 07 2021 at 19:22)</a>:</h4>
<p>the LLVM IR for a gather: <a href="https://llvm.org/docs/LangRef.html#llvm-masked-gather-intrinsics">https://llvm.org/docs/LangRef.html#llvm-masked-gather-intrinsics</a></p>



<a name="237882875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237882875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237882875">(May 07 2021 at 20:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237850685">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237713834">said</a>:</p>
<blockquote>
<p>yeah, it basically is just "a vector of pointers"</p>
</blockquote>
<p>i think you've been hit by the confusion inherent in x86's many addressing modes. in practice this is still base address and 32 bit indices (for the v32x).</p>
</blockquote>
<p>Yeah I noticed that after I stared at it for a bit.</p>



<a name="237883680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237883680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237883680">(May 07 2021 at 20:13)</a>:</h4>
<p>That was what the "totally exotic memory encoding!" remark was.</p>
<p>At the moment, I believe we should provide safe, yes, checked <code>gather</code> and <code>scatter</code> functions that take <code>&amp;[T]</code> | <code>&amp;mut [T]</code> and a vector of indices, and think more about the "vector of pointers" thing and mb work towards providing an API for that <em>eventually</em>.</p>



<a name="237883972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237883972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237883972">(May 07 2021 at 20:15)</a>:</h4>
<p>I agree. As cools as scatter/gather are they are fairly niche</p>



<a name="237884259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237884259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237884259">(May 07 2021 at 20:17)</a>:</h4>
<p>I think the only architecture that we support that even has it is AVX</p>



<a name="237889735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237889735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237889735">(May 07 2021 at 21:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237884259">said</a>:</p>
<blockquote>
<p>I think the only architecture that we support that even has it is AVX</p>
</blockquote>
<p>all of AVX2 (gather only), AVX512, ARM SVE, RVV, and SimpleV support gather/scatter</p>



<a name="237890330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237890330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237890330">(May 07 2021 at 21:08)</a>:</h4>
<p>Well, we can't support SVE</p>



<a name="237895764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237895764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237895764">(May 07 2021 at 21:55)</a>:</h4>
<p>hmm.</p>



<a name="237897657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237897657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237897657">(May 07 2021 at 22:10)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> I am not so sure. I think we can, actually. I think we might enjoy a situation where the way our API is defined, it favors fixed-width "strip-mining" slightly more, but it aligns somewhat with the LLVM understanding of what the RVV/SVE vectors are, which is, as I understand it, "a possibly dynamic entity, but fixed-width during actual invocation". So I think on Arm and RISC-V, if LLVM thinks we're going to benefit from going SVE or RVV, we could probably generate "dynamic" vectors.</p>



<a name="237897972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237897972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237897972">(May 07 2021 at 22:12)</a>:</h4>
<p>Yeah I should have clarified that I was referring to fixed-width vectors</p>



<a name="237898008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898008">(May 07 2021 at 22:13)</a>:</h4>
<p>We could do something with vscale but it will look very different</p>



<a name="237898177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898177">(May 07 2021 at 22:14)</a>:</h4>
<p>Well yeah, I mostly mean that I think our stuff is actually in a kinda good spot for VScale stuff.</p>



<a name="237898368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898368">(May 07 2021 at 22:16)</a>:</h4>
<p>Generally yes, but it doesn't replace it</p>



<a name="237898388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898388">(May 07 2021 at 22:16)</a>:</h4>
<p>The vscale scatter/gather is definitely not the same as a fixed vector</p>



<a name="237898418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898418">(May 07 2021 at 22:16)</a>:</h4>
<p>well yeah.</p>



<a name="237898425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898425">(May 07 2021 at 22:16)</a>:</h4>
<p>Though it's similar in many ways</p>



<a name="237898529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898529">(May 07 2021 at 22:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237897972">said</a>:</p>
<blockquote>
<p>Yeah I should have clarified that I was referring to fixed-width vectors</p>
</blockquote>
<p>I think we probably can get SVE to work with fixed-length vectors, LLVM currently gets RVV to work with fixed-length vectors (if you pass the flag allowing it to assume RVV supports at least 128-bit vectors): <a href="https://llvm.godbolt.org/z/WejPcoxro">https://llvm.godbolt.org/z/WejPcoxro</a></p>



<a name="237898546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898546">(May 07 2021 at 22:18)</a>:</h4>
<p>My point was more that if you're using for example f32x4 most architectures don't have scatter/gather anyway</p>



<a name="237898600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898600">(May 07 2021 at 22:19)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> how would that work without multiversioning?</p>



<a name="237898708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898708">(May 07 2021 at 22:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/237898600">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="229517">Jacob Lifshay</span> how would that work without multiversioning?</p>
</blockquote>
<p>just like enabling AVX2 works without multiversioning -- the code just assumes the vectors are long enough and crashes if they aren't</p>



<a name="237898715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898715">(May 07 2021 at 22:20)</a>:</h4>
<p>Or is it assuming the vscale is 1</p>



<a name="237898804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898804">(May 07 2021 at 22:21)</a>:</h4>
<p>Oh, so it is multiversioning, but you can specify a specific vscale as a "feature"?</p>



<a name="237898830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898830">(May 07 2021 at 22:21)</a>:</h4>
<p>In that case I'm more excited for SVE.</p>



<a name="237898838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898838">(May 07 2021 at 22:21)</a>:</h4>
<p>yeah iirc (though that's not all implemented for SVE yet)</p>



<a name="237898911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898911">(May 07 2021 at 22:22)</a>:</h4>
<p>So you might have say sve1, sve2, sve4 or whatever you want to call them</p>



<a name="237898936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898936">(May 07 2021 at 22:22)</a>:</h4>
<p>for RVV you just pass <code>-riscv-v-vector-bits-min=128</code> to llvm</p>



<a name="237898970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237898970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237898970">(May 07 2021 at 22:22)</a>:</h4>
<p>Hmm interesting.</p>



<a name="237899049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899049">(May 07 2021 at 22:23)</a>:</h4>
<p>yeah, kinda...now that I look, llvm ir has a function annotation <code>vscale_range(min, [max])</code> which tells llvm it can assume <code>vscale</code> is in that range</p>



<a name="237899157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899157">(May 07 2021 at 22:24)</a>:</h4>
<p>So might take some work but it could be treated effectively like a target feature</p>



<a name="237899172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899172">(May 07 2021 at 22:25)</a>:</h4>
<p>yup!</p>



<a name="237899244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899244">(May 07 2021 at 22:25)</a>:</h4>
<p>Yeah, basically it seems to me that our vectors can exploit dynamic lengths, basically, in spite of having a static size. And SVE implies Neon, so you definitely have at least 128 bits on Arm.</p>



<a name="237899255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899255">(May 07 2021 at 22:26)</a>:</h4>
<p>That's definitely interesting</p>



<a name="237899320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899320">(May 07 2021 at 22:26)</a>:</h4>
<p>I think we probably want dynamic vectors, too (which on static platforms would just be the native size, I think)</p>



<a name="237899345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899345">(May 07 2021 at 22:26)</a>:</h4>
<p>But generally I think static vectors are more useful</p>



<a name="237899390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/237899390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#237899390">(May 07 2021 at 22:27)</a>:</h4>
<p>Yeah, that can be figured out as things go along.<br>
I think having static but architecture-neutral sizes is the Right Choice.</p>



<a name="238039336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nicoo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039336">(May 09 2021 at 14:27)</a>:</h4>
<p>Hi!  I was looking at <code>core_simd</code>, as I'm trying to vectorize some parts of <code>uu_factor</code>, but I cannot find any documentation on how to use that library.  There's <a href="https://rust-lang.github.io/stdsimd/core_simd">the reference docs</a> but it doesn't really help  &gt;_&gt;'</p>
<p>In particular, I'm trying to find how to do masked point-wise wrapping multiplications (against a single scalar) and comparisons, combining masks with logical operators, etc.</p>



<a name="238039407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039407">(May 09 2021 at 14:28)</a>:</h4>
<p>The docs on <code>docs.rs</code> are for an old unrelated library, not for the current stdsimd as found in <a href="https://github.com/rust-lang/stdsimd">https://github.com/rust-lang/stdsimd</a>.</p>



<a name="238039447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nicoo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039447">(May 09 2021 at 14:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/257879-project-portable-simd/topic/SIMD.20Pointers/near/238039407">said</a>:</p>
<blockquote>
<p>The docs on <code>docs.rs</code> are for an old unrelated library</p>
</blockquote>
<p>Oops, sorry, I was looking at <a href="https://rust-lang.github.io/stdsimd/core_simd">https://rust-lang.github.io/stdsimd/core_simd</a></p>



<a name="238039569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039569">(May 09 2021 at 14:31)</a>:</h4>
<p>Wrapping multiplication is implemented with the plain <code>*</code> operator. To do anything masked you need to use the <code>select</code> function</p>



<a name="238039640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nicoo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039640">(May 09 2021 at 14:32)</a>:</h4>
<p>Thanks!  Where is <code>select</code> documented?  I saw the <code>Select</code> trait but nothing about the actual method</p>



<a name="238039697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20Pointers/near/238039697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20Pointers.html#238039697">(May 09 2021 at 14:33)</a>:</h4>
<p>It's a method on all masks, you use it like <code>mask.select(true_values, false_values)</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>